package com.pg.controller.dd;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pg.entity.dd.EipSalesOrderLinenum;
import com.pg.service.EipSalesOrderLinenumService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.UUID;

/**
 * <p>
 * 销售订单行项目前端控制器
 * </p>
 *
 * @author likl
 * @since 2020-07-06
 */
@Api(tags = "销售订单")
@RestController
@RequestMapping("/eipSalesOrderLinenum")
//@Slf4j
public class EipSalesOrderLinenumController extends JeecgController<EipSalesOrderLinenum, EipSalesOrderLinenumService> {

    @Autowired
    private EipSalesOrderLinenumService eipSalesOrderLinenumService;

    /**
     * 添加 销售订单行项目
     *
     * @param eipSalesOrderLinenum 销售订单行项目
     * @return 是否成功
     */
    @ApiOperation("添加 销售订单行项目")
    @AutoLog(value = "添加 销售订单行项目")
    @RequestMapping("/add")
    public Result<?> add(@RequestBody EipSalesOrderLinenum eipSalesOrderLinenum) {
        eipSalesOrderLinenum.setPuid(UUID.randomUUID().toString());
        eipSalesOrderLinenumService.save(eipSalesOrderLinenum);
        return Result.ok("添加成功！");
    }

    /**
     * 编辑 销售订单行项目
     *
     * @param eipSalesOrderLinenum 销售订单行项目
     * @return 是否成功
     */
    @ApiOperation("编辑 销售订单行项目")
    @AutoLog(value = "编辑 销售订单行项目")
    @RequestMapping("/edit")
    public Result<?> edit(@RequestBody EipSalesOrderLinenum eipSalesOrderLinenum) {
        eipSalesOrderLinenumService.updateById(eipSalesOrderLinenum);
        return Result.ok("修改成功！");
    }

    /**
     * 通过id删除 销售订单行项目
     *
     * @param id 全库唯一码
     * @return 是否成功
     */
    @ApiOperation("通过id删除 销售订单行项目")
    @AutoLog(value = "通过id删除 销售订单行项目")
    @DeleteMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
        eipSalesOrderLinenumService.removeById(id);
        return Result.ok("删除成功!");
    }

    /**
     * 分页列表查询 销售订单行项目
     *
     * @param eipSalesOrderLinenum 销售订单行项目
     * @param pageNo               起始页
     * @param pageSize             每页页数
     * @param req                  参数
     * @return 分页数据
     */
    @ApiOperation("分页列表查询 销售订单行项目")
    @AutoLog(value = "分页列表查询 销售订单行项目")
    @GetMapping("/list")
    public Result<?> selectForList(
            EipSalesOrderLinenum eipSalesOrderLinenum,
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            HttpServletRequest req) {
        if ("undefined".equals(eipSalesOrderLinenum.getImanXsdd())) {
            eipSalesOrderLinenum.setImanXsdd(null);
        }
        Page<EipSalesOrderLinenum> page = new Page<EipSalesOrderLinenum>(pageNo, pageSize);
        QueryWrapper<EipSalesOrderLinenum> queryWrapper = new QueryWrapper<EipSalesOrderLinenum>(eipSalesOrderLinenum);
        IPage<EipSalesOrderLinenum> pageList = eipSalesOrderLinenumService.page(page, queryWrapper);
        return Result.ok(pageList);
    }

    /**
     * 通过excel导入数据 销售订单行项目
     *
     * @param request  参数
     * @param response 响应
     * @return 是否成功
     */
    @ApiOperation("通过excel导入数据 销售订单行项目")
    @AutoLog(value = "通过excel导入数据 销售订单行项目")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, EipSalesOrderLinenum.class);
    }

    /**
     * 导出excel 销售订单行项目
     *
     * @param request              参数
     * @param eipSalesOrderLinenum 销售订单行项目
     */
    @ApiOperation("导出excel 销售订单行项目")
    @AutoLog(value = "导出excel 销售订单行项目")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(EipSalesOrderLinenum eipSalesOrderLinenum, HttpServletRequest request) {
        return super.exportXls(request, eipSalesOrderLinenum, EipSalesOrderLinenum.class, "eip_sales_order_linenum");

    }
}

